<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\common\controller\System;
use app\common\enum\Shipment;

/**
 * 合并订单
 *
 */
class Order extends System {
    /**
     * Order模型对象
     * @var \app\admin\model\Order
     */
    protected object $model;

    protected array|string $preExcludeFields = ['id', 'create_time'];

    protected array|string $quickSearchField = ['id'];

    public function initialize():void {
        parent::initialize();
        $this->model = new \app\admin\model\Order;
    }

    public function index(): void {

        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->param('select')) {
            $this->select();
        }
        $this->withJoinTable = ['user'];
        list($where, $alias, $limit, $order) = $this->queryBuilder();
        $res = $this->model
            ->field($this->indexField)
            ->withJoin($this->withJoinTable, $this->withJoinType)
            ->alias($alias)
            ->where($where)
            ->order($order)
            ->paginate($limit);

        $list = $res->items();

        foreach($list as &$val){
            $seller = explode(',', $val['seller']);
            $val['seller'] = $seller[1] . "/{$val['house_number']}<br>({$val['seller_name']})";

        }

        $this->success('', [
            'list' => $list,
            'total' => $res->total(),
            'remark' => get_route_remark(),
        ]);
    }


    /**
     * 若需重写查看、编辑、删除等方法，请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
     */
}